package com.study.designPattern.create.prototype;

import java.util.Hashtable;

/**
 * @author ysy
 * @version 1.0
 * @Title: CarCache
 * @Note <b>ProjectName:</b> Pre-research
 * <br><b>PackageName:</b> com.study.designPattern.create.prototype
 * <br><b>ClassName:</b>
 * <br><b>Date:</b>

 */
public class CarCache {
    // 缓存对象
    private static Hashtable<String, CloneableCar> carMap = new Hashtable<String, CloneableCar>();

    // 从map中获取缓存对象
    public static CloneableCar getCar(String carId) throws CloneNotSupportedException {
        CloneableCar cloneableCar = carMap.get(carId);
        return (CloneableCar)cloneableCar.clone();
    }

    public static void loadCache() {
        Benz benz = new Benz();
        benz.setId("1");
        carMap.put(benz.getId(), benz);

        Honda honda = new Honda();
        honda.setId("2");
        carMap.put(honda.getId(), honda);
    }
}
